import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { _HttpClient } from '@delon/theme';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { AdEditComponent } from '../ad-edit/ad-edit.component';
import { STData } from '@delon/abc';
import { type } from 'os';
import { from } from 'rxjs';
import { ACLService } from '@delon/acl';

@Component({
  selector: 'ad-list',
  templateUrl: './ad-list.component.html',
  styles:[]
})
export class AdListComponent implements OnInit {
  @ViewChild('st', { static: false }) st: TablePageComponent;
  selectData: any[];
  loading = false;
  addFlag:boolean = this.aclService.canAbility("ad-manage/add");//检查用户按钮权限
  editFlag:boolean =  this.aclService.canAbility("ad-manage/edit");
  delFlag:boolean =  this.aclService.canAbility("ad-manage/delete");
  addUserInfo = {
    userAccount: '',
    userPassword: '',
    userName: '',
    roles: [],
    depts: []
  };
  config: SPage = {
    columns: [
      {
        index: 'title',
        title: '标题',
        filter: {
          placeholder: '请输入标题',
          type: 'string'
        }
      },
      {
        index: 'type',
        title: '类别',
        type: ColumnType.tag,
        tag:{
          1:{text:'文字'},
          2:{text:'图片'},
          3:{text:'视频'}
        },
        filter:{
          placeholder: '请选择类别',
          type: 'select',
          items: [
            {label: '文字', value: 1},
            {label: '图片', value: 2},
            {label: '视频', value: 3}
          ]
        }
      },
      {
        index: 'beginDate',
        title: '开始日期',
      },
      {
        index: 'endDate',
        title: '结束日期',
      },
      {
        index: 'beginTime',
        title: '开始时间',
      },
      {
        index: 'endTime',
        title: '结束时间',
      },
      {
        index: 'fileUrl',
        title: '文件',
      },
      {
        index: 'desc',
        title: '描述'
      }
    ],
    showCheckBox: false,
    
    editBtn:[
      {title: '修改', iif: () => this.editFlag},
      {title: '删除', iif: () => this.delFlag}
    ],
    reqUrl:'/core/record/inout/page'
  }
  constructor(private http: _HttpClient,  private api: ApiService, private modal: NzModalService,private img: ElementRef, private message: NzMessageService,private aclService: ACLService) { }
  
  imageInfo(imageUrl?: string): void {
    
    const modal = this.modal.create({
      nzTitle: '图片信息',
      nzContent: '<img width="100%" src="'+imageUrl+'">',
      nzWidth: 800,
      nzFooter: null
    })
  }
  
  dataProcess(data: STData[]){
    console.log(data);
    let returnData = [
      {id:1,title:'标题1',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'',desc:'描述哦！'},
      {id:1,title:'标题2',type:2,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦1！'},
      {id:1,title:'标题3',type:3,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.mp4',desc:'描述哦2！'},
      {id:1,title:'标题4',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦3！'},
      {id:1,title:'标题5',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦4！'},
      {id:1,title:'标题6',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦5！'},
      {id:1,title:'标题7',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦6！'},
      {id:1,title:'标题8',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦7！'},
      {id:1,title:'标题9',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦8！'},
      {id:1,title:'标题10',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦9！'},
      {id:1,title:'标题11',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦10！'},
      {id:1,title:'标题12',type:1,beginDate:'2021-02-01',endDate:'2021-02-02',beginTime:'12:23:12',endTime:'22:12:00',fileUrl:'/file/abc.png',desc:'描述哦11！'},
    ];
    return returnData;
  }
  // 编辑功能开始
  editDic(type: 0 | 1 = 0, _param?: object): void {
    console.log(type);
    const title = type ? '修改':'新增';
    const modal = this.modal.create({
      nzTitle: title,
      nzContent: AdEditComponent,
      nzWidth: 1200,
      nzComponentParams: {
        type,
        _param
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
    modal.afterClose.subscribe(res => {
      if (res === 'ok') {
        this.st.reload();
      }
    })
  }

  operate(e: any): void {
    if (e.title === '删除') {
      this.message.success('删除成功');
    }
    if(e.title === '修改'){
      this.editDic(1, e.data);
    }
  }
  ngOnInit() {

  }

}
